package com.nbst.controller.base;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.nbst.comnutil.NormalResult;
import com.nbst.comnutil.Tools;
import com.nbst.dao.mapper.mes.WorkCenterMapper;
import com.nbst.model.base.Department;
import com.nbst.service.base.IDepartmentService;

/**
 * @ClassName: DepartmentAndWorkShopController
 * @Description: 部门与车间
 * @author King
 * @date 2018年11月7日
 * 
 */
@RestController
@RequestMapping("/deptOrWorkShop")
public class DeptAndWorkShopController {
	@Autowired
	IDepartmentService departmentService;

	@Autowired
	WorkCenterMapper workCenterMapper;

	/**
	 * 获取部门列表
	 * 
	 * @param record
	 * @param offset
	 * @param row
	 * @return Object
	 * @author King
	 * @date 2018年11月7日
	 */
	@GetMapping("/getDepartment.action")
	public Object getDepartment(Department record, @RequestParam(required = false, defaultValue = "1") Integer offset,
			@RequestParam(required = false, defaultValue = "1000") Integer row) {
		Map<String,Object> map = Tools.transBean2Map(record);
		map.put("fDProperty", 1071);
		Page page = PageHelper.startPage(Tools.getPageNum(offset, row),row, true);
		List<Department> list = departmentService.findByCondition(map);
		NormalResult result = new NormalResult();
		result.setCode("0000");
		result.setMessage("操作成功");
		result.setRows(list);
		result.setTotal(page.getTotal());
		return result;
	}

	/**
	 * 获取车间列表
	 * 
	 * @param record
	 * @param offset
	 * @param row
	 * @return Object
	 * @author King
	 * @date 2018年11月7日
	 */
	@GetMapping("/getWorkShop.action")
	public Object getWorkShop(Department record, @RequestParam(required = false, defaultValue = "1") Integer offset,
			@RequestParam(required = false, defaultValue = "1000") Integer row) {
		Map<String,Object> map = Tools.transBean2Map(record);
		map.put("fDProperty", 1070);
		Page page = PageHelper.startPage(Tools.getPageNum(offset, row),row, true);
		List<Department> list = departmentService.findByCondition(map);
		NormalResult result = new NormalResult();
		result.setCode("0000");
		result.setMessage("操作成功");
		result.setRows(list);
		result.setTotal(page.getTotal());
		return result;
	}
	
	/**
	 * 获取部门与车间树
	 * @return
	 * Object 
	 * @author King
	 * @date 2018年11月7日
	 */
	@GetMapping("/getDeptAndWorkshopTree.action")
	public Object getWorkShop() {
		return departmentService.getDeptAndWorkShopTree();
	}

}
